package pl.lodz.p.browarex.util;

import java.beans.PropertyEditorSupport;

import pl.lodz.p.browarex.model.Ingredient;
import pl.lodz.p.browarex.service.GenericService;
import pl.lodz.p.browarex.service.IngredientService;

public class IngredientEditor extends PropertyEditorSupport{
	
	private final GenericService<Ingredient, Long> ingredientService;
	 
    public IngredientEditor(GenericService<Ingredient, Long> ingredientService2) {
        this.ingredientService = ingredientService2;
    }
 
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		Ingredient ingredient = ingredientService.find(Long.parseLong(text));
        setValue(ingredient);
	}
}
